<template>
  <a-layout-header class="new-nav-bar">
    <div class="logo-container">Noodle系统</div>
    <div class="tab-container"
         @click="switchTab">
      <div :class="['tab-item', isCourse ? 'active' : '']">课程</div>
      <div :class="['tab-item', isQuestion ? 'active' : '']">问答</div>
    </div>
    <div class="user-container">
      <user-avatar />
    </div>
  </a-layout-header>
</template>

<script>
import UserAvatar from './UserAvatar'

export default {
  name: 'NewNavBar',
  data () {
    return {
      env: ''
      // isCourse: true,
    }
  },
  computed: {
    isCourse: function () {
      return this.$route.path.split('/')[3] === 'courses'
    },
    isQuestion: function () {
      return this.$route.path.split('/')[3] === 'question'
    },
    isProgress: function () {
      return this.$route.path.split('/')[3] === 'progress'
    }
  },
  components: {
    UserAvatar
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      const curRouter = this.$route.path.split('/')
      this.env = curRouter[2]
    },
    switchTab (e) {
      if (e.target.innerHTML === '课程') {
        if (!(this.$route.path.split('/')[3] === 'courses')) {
          this.$router.push('/train/' + this.env + '/courses')
        }
      } else if (e.target.innerHTML === '问答'){
        if (!(this.$route.path.split('/')[3] === 'question')) {
          this.$router.push('/train/' + this.env + '/question')
        }
      }else if (e.target.innerHTML === '学生进度'){
        if (!(this.$route.path.split('/')[3] === 'progress')) {
          this.$router.push('/train/' + this.env + '/progress')
        }
      }
    }
  }
}
</script>

<style lang="less" scoped>
//@import '~ant-design-vue/es/style/themes/default.less';
@import "../../styles/global.less";


.new-nav-bar {
  //background: transparent;
  background: white;
  position: fixed;
  z-index: 100;
  width: 100%;
  display: flex;
  height: 90px;
  line-height: 90px;
  padding: 0;
  align-items: center;

  .logo-container {
    font-family: PingFang SC, sans-serif;
    font-weight: bold;
    color: #000000;
    font-size: 18px;
    line-height: 26px;

    width: 10%;
    /*margin-left: 0.5%;*/
  }

  .tab-container {
    flex: 1;
    height: 25px;
    font-size: 18px;
    font-family: PingFang SC, sans-serif;
    font-weight: 400;
    line-height: 25px;
    .tab-item {
      display: inline;
      color: #929292;
      margin: 0 1%;
    }
    .tab-item:hover {
      cursor: pointer;
    }
    .active {
      color: #1bd0a2;
    }
  }
  .user-container {
    justify-self: right;
    width: 7.5%;
    /*margin-right: 2%;*/
    .user-detail {
      display: flex;
      justify-content: center;
      align-items: center;
      .user-name {
        margin-left: 10px;
      }
    }
  }
}
.logout {
  color: @btn-danger-bg;
}
</style>
